import request from '@/utils/http'
import { BaseResponse } from '@/types/api'

interface LoginParams {
  username: string
  password: string
}

interface RegisterParams {
  username: string
  password: string
  contactPerson: string,
  promoterCode: string
}

interface UserListParams {
  current?: number
  size?: number
}

export class UserService {
  // 登录
  static login(params: LoginParams) {
    return request.get<BaseResponse>({
      url: '/auth/login',
      params
    })
  }

  // 获取用户信息
  static getUserInfo() {
    return request.get<BaseResponse>({
      url: '/users/me',
      requestOptions: { errorMessageMode: 'modal' }
    })
  }

  // 注册
  static register(data: RegisterParams) {
    return request.post<BaseResponse>({
      url: '/auth/reg/user',
      data
    })
  }

  // 获取用户列表
  static getUserList(params?: UserListParams) {
    return request.get<BaseResponse>({
      url: '/api/user/list',
      params
    })
  }
}
